package com.acwing.partition37;

import java.io.*;

/**
 * @author rkc
 * @date 2022/7/21 9:13
 */
public class AC3652最大连续子序列 {

    private static final int N = 100010;
    private static int[] w = new int[N];
    private static int n;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        while (true) {
            String in = reader.readLine();
            if (in == null || in.isEmpty()) break;
            n = Integer.parseInt(in.trim());
            String[] ss = reader.readLine().split(" ");
            for (int i = 0; i < n; i++) w[i] = Integer.parseInt(ss[i]);
            int ans = 0, l = 0, r = 0;
            for (int i = n - 1, f = 0, g = n - 1; i >= 0; i--) {
                if (f <= 0) {
                    f = 0;
                    g = i;
                }
                f += w[i];
                if (f >= ans) {
                    ans = f;
                    l = i;
                    r = g;
                }
            }
            writer.write(String.format("%d %d %d\n", ans, l, r));
        }
        writer.flush();
    }
}
